/**
 * 菜单js
 */
    var target = $("#dg").attr("title");
	var url;

	function newUser() {
		$('#dlg').dialog('open').dialog('setTitle', '新建 ' + target);
		$('#fm').form('clear');
		url = '/curd/create.action?target=' + target;
	}

	function editUser() {
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$('#dlg').dialog('open').dialog('setTitle', '编辑 ' + target);
			$('#fm').form('load', row);
			url = '/curd/update.action?target=' + target;
		}
	}

	function saveUser() {
		$('#fm').form('submit', {
			url : url,
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.errorMsg) {
					$.messager.show({
						title : 'Error',
						msg : result.errorMsg
					});
				} else {
					$('#dlg').dialog('close'); // close the dialog  
					$('#dg').datagrid('reload'); // reload the user data  
				}
			}
		});
	}
	function destroyUser() {
		url = '/curd/delete.action?target=' + target;
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('Confirm', '确认删除此记录', function(r) {
				if (r) {
					$.post(url, row, function(result) {
						if (result.success) {
							$('#dg').datagrid('reload'); // reload the user data  
						} else {
							$.messager.show({ // show error message  
								title : 'Error',
								msg : result.errorMsg
							});
						}
					}, 'json');
				}
			});
		}
	}